/********************************************************************
* Copyright (c) 2013,TGS,All rights reserved.
* fileName:	MapTool.h	
* created:	2013/04/23 17:45

* version:	1.6
* detail: 
*********************************************************************/

#pragma once

#include <QCursor>
#include <QString>
#include <QObject>

class QKeyEvent;
class QMouseEvent;
class QPoint;
class QAction;
class QAbstractButton;
class QWheelEvent;

namespace TGS{
namespace GeoMath{

	class Point;
}
}

namespace TGS{
namespace MapControl{

class MapLayer;
class MapCanvas;

/** \ingroup gui
 * Abstract base class for all map tools.
 * Map tools are user interactive tools for manipulating the
 * map canvas. For example map pan and zoom features are
 * implemented as map tools.
 */
class MapTool : public QObject
{
public:
	typedef TGS::GeoMath::Point Point;
public:

    //! virtual destructor
    virtual ~MapTool();
public:
    //! Mouse move event for overriding. Default implementation does nothing.
    virtual void canvasMoveEvent( QMouseEvent * e );

	virtual void canvasWheelEvent( QWheelEvent *e );

    //! Mouse double click event for overriding. Default implementation does nothing.
    virtual void canvasDoubleClickEvent( QMouseEvent * e );

    //! Mouse press event for overriding. Default implementation does nothing.
    virtual void canvasPressEvent( QMouseEvent * e );

    //! Mouse release event for overriding. Default implementation does nothing.
    virtual void canvasReleaseEvent( QMouseEvent * e );

    //! Key event for overriding. Default implementation does nothing.
    virtual void keyPressEvent( QKeyEvent* e );

    //! Key event for overriding. Default implementation does nothing.
    //! Added in version 1.1
    virtual void keyReleaseEvent( QKeyEvent* e );

    //! Called when rendering has finished. Default implementation does nothing.
    virtual void renderComplete();


    /** Use this to associate a QAction to this maptool. Then when the setMapTool
     * method of mapcanvas is called the action state will be set to on.
     * Usually this will cause e.g. a toolbutton to appear pressed in and
     * the previously used toolbutton to pop out. */
    void setAction( QAction* action );

    /** Return associated action with map tool or NULL if no action is associated */
    QAction* action();

    /** Use this to associate a button to this maptool. It has the same meaning
     * as setAction() function except it works with a button instead of an QAction. */
    void setButton( QAbstractButton* button );

    /** Return associated button with map tool or NULL if no button is associated */
    QAbstractButton* button();

	virtual void reset();

    /** Check whether this MapTool performs a zoom or pan operation.
     * If it does, we will be able to perform the zoom  and then
     * resume operations with the original / previously used tool.*/
    virtual bool isTransient();

    /** Check whether this MapTool performs an edit operation.
     * If it does, we will deactivate it when editing is turned off
     */
    virtual bool isEditTool();

    //! called when set as currently active map tool
    virtual void activate();

    //! called when map tool is being deactivated
    virtual void deactivate();

    //! returns pointer to the tool's map canvas
    MapCanvas* canvas();

	void setCursor(const QCursor& cursor);

protected:

    //! constructor takes map canvas as a parameter
    MapTool( MapCanvas* canvas );

    //! transformation from screen coordinates to map coordinates
    Point toMapCoordinates( const QPoint& point );

    //! transformation from map coordinates to screen coordinates
    QPoint toCanvasCoordinates( const Point& point );
private:
    //! pointer to map canvas
    MapCanvas* _canvas;

    //! cursor used in map tool
    QCursor _cursor;

    //! optionally map tool can have pointer to action
    //! which will be used to set that action as active
    QAction* _action;

    //! optionally map tool can have pointer to a button
    //! which will be used to set that action as active
    QAbstractButton* _button;

};

}//MapControl
}//TGS